//计算距离
function distanceWith(num) {
  if (num >= 1 && num < 999999999) {
    return '距您' + num + 'km'
  } else if (num > 0 && num < 1) {
    var distance = num * 1000
    distance = Math.round(distance * 100) / 100
    return '距您' + distance + 'm'
  } else if (num == 0) {
    return '距您0m'
  }
}
//计算已售数量单位转换
function soldQuantity(num) {
  if (num >= 10000 && num != '') {
    // num = Number((num / 10000).toString().match(/^\d+(?:\.\d{0,1})?/)) + '万+'
    num = (num / 10000).toString().match(/^\d+(?:\.\d{0,1})?/) + '万+'
  }
  return num
}
// 订单明细状态 status 1 待使用 2 已使用 3 退款处理中 4 已退款
function statusInfo(status) {
  var name = ''
  if (status == 1) {
    name = '待使用'
  } else if (status == 2) {
    name = '已使用'
  } else if (status == 3) {
    name = '退款处理中'
  } else if (status == 4) {
    name = '已退款'
  }
  console.log(name)
  return name
}
//乘法计算已售数量单位转换
function accMul(num1, num2) {
  var num = Math.round((num1 * num2) * 100) / 100
  return num
}
//除法
function accDiv(num1, num2) {
  var num = Math.round((num1 / num2) * 100) / 100
  return num
}
// 减法
function accSub(arg1,arg2){ 
  var r1,r2,m,n; 
  try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0} 
  try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0} 
  m=Math.pow(10,Math.max(r1,r2)); 
  //last modify by deeka 
  //动态控制精度长度 
  n=(r1>=r2)?r1:r2; 
  return ((arg2*m-arg1*m)/m).toFixed(n); 
}
// 加法
function accAdd(arg1,arg2){ 
  var r1,r2,m; 
  try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0} 
  try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0} 
  m=Math.pow(10,Math.max(r1,r2)); 
  return (arg1*m+arg2*m)/m; 
}

module.exports = {
  statusInfo: statusInfo,
  distanceWith: distanceWith,
  soldQuantity: soldQuantity,
  accMul: accMul,
  accDiv: accDiv,
  accAdd: accAdd,
  accSub: accSub,
};